package com.ruoyi.portal.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.portal.domain.PorContact;
import com.ruoyi.portal.service.IPorContactService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商务合作Controller
 *
 * @author cjie
 * @date 2021-07-12
 */
@Api(tags = " 商务合作")
@RestController
@RequestMapping("/porContact")
public class PorContactController extends BaseController {
    @Autowired
    private IPorContactService porContactService;

    /**
     * 查询商务合作列表
     */
    @ApiOperation(value="查询商务合作列表", notes="查询商务合作列表")
    @GetMapping("/list")
    public TableDataInfo list(PorContact porContact) {
        startPage();
        List<PorContact> list = porContactService.selectPorContactList(porContact);
        return getDataTable(list);
    }

    /**
     * 导出商务合作列表
     */
    @ApiOperation(value="导出商务合作列表", notes="导出商务合作列表")
    @PreAuthorize(hasPermi = "portal:porContact:export")
    @Log(title = "商务合作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PorContact porContact) throws IOException {
        List<PorContact> list = porContactService.selectPorContactList(porContact);
        ExcelUtil<PorContact> util = new ExcelUtil<PorContact>(PorContact.class);
        util.exportExcel(response, list, "商务合作数据");
    }
    /**
     * 获取商务合作详细信息
     */
    @ApiOperation(value="获取商务合作详细信息", notes="获取商务合作详细信息")
    @PreAuthorize(hasPermi = "portal:porContact:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(porContactService.selectPorContactById(id));
    }

    /**
     * 新增商务合作
     */
    @ApiOperation(value="新增商务合作", notes="新增商务合作")
    @PreAuthorize(hasPermi = "portal:porContact:add")
    @Log(title = "商务合作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PorContact porContact) {
        return toAjax(porContactService.insertPorContact(porContact));
    }

    /**
     * 修改商务合作
     */
    @ApiOperation(value="修改商务合作", notes="修改商务合作")
    @PreAuthorize(hasPermi = "portal:porContact:edit")
    @Log(title = "商务合作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PorContact porContact) {
        return toAjax(porContactService.updatePorContact(porContact));
    }

    /**
     * 删除商务合作
     */
    @ApiOperation(value="删除商务合作", notes="删除商务合作")
    @ApiImplicitParam(name = "ids", value = "商务合作ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "portal:porContact:remove")
    @Log(title = "商务合作", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(porContactService.deletePorContactByIds(ids));
    }
}
